<?php
namespace Amis\form;
class InputText extends FormItem
{
    public string $type = 'input-text';

    public function options(array $options = [])
    {
        $this->options = $options;
        return $this;
    }

    public function source($api)
    {
        $this->source = $api;
        return $this;
    }

    public function autoComplete(string $autoComplete)
    {
        $this->autoComplete = $autoComplete;
        return $this;
    }

    public function multiple(bool $multiple = false)
    {
        $this->multiple = $multiple;
        return $this;
    }

    public function delimiter(string $delimiter = ',')
    {
        $this->delimiter = $delimiter;
        return $this;
    }

    public function labelField(string $labelField)
    {
        $this->labelField = $labelField;
        return $this;
    }

    public function valueField(string $valueField)
    {
        $this->valueField = $valueField;
        return $this;
    }

    public function joinValues(bool $joinValues = true)
    {
        $this->joinValues = $joinValues;
        return $this;
    }

    public function extractValue(bool $extractValue = false)
    {
        $this->extractValue = $extractValue;
        return $this;
    }

    /**
     * 输入框附加组件，比如附带一个提示文字，或者附带一个提交按钮。
     * addOn.type    string        请选择 text 、button 或者 submit。
     * addOn.label    string        文字说明
     * addOn.position    'left' | 'right'    'right'    addOn 位置
     * addOn.xxx    string        其他参数请参考按钮文档
     * @param $addOn
     * @return $this
     */
    public function addOn($addOn)
    {
        $this->addOn = $addOn;
        return $this;
    }

    /**
     * 是否去除首尾空白文本。
     * @param bool $trimContents
     * @return $this
     */
    public function trimContents(bool $trimContents = true)
    {
        $this->trimContents = $trimContents;
        return $this;
    }

    /**
     * 是否可以创建，默认为可以，除非设置为 false 即只能选择选项中的值
     * @param bool $creatable
     * @return $this
     */
    public function creatable(bool $creatable)
    {
        $this->creatable = $creatable;
        return $this;
    }

    /**
     * 是否可清除
     * @param bool $clearable
     * @return $this
     */
    public function clearable(bool $clearable)
    {
        $this->clearable = $clearable;
        return $this;
    }

    public function resetValue(string $resetValue = '')
    {
        $this->resetValue = $resetValue;
        return $this;
    }

    /**
     * 前缀
     * @param string $prefix
     * @return $this
     */
    public function prefix(string $prefix)
    {
        $this->prefix = $prefix;
        return $this;
    }

    /**
     * 后缀
     * @param string $suffix
     * @return $this
     */
    public function suffix(string $suffix)
    {
        $this->suffix = $suffix;
        return $this;
    }

    /**
     * 是否显示计数器
     * @param bool $showCounter
     * @return $this
     */
    public function showCounter(bool $showCounter)
    {
        $this->showCounter = $showCounter;
        return $this;
    }

    /**
     * 限制最小字数
     * @param int $minLength
     * @return $this
     */
    public function minLength(int $minLength)
    {
        $this->minLength = $minLength;
        return $this;
    }

    /**
     * 限制最大字数
     * @param int $maxLength
     * @return $this
     */
    public function maxLength(int $maxLength)
    {
        $this->maxLength = $maxLength;
        return $this;
    }

    /**
     * 自动转换值，可选 transform: { lowerCase: true, upperCase: true }
     * @param int $transform
     * @return $this
     */
    public function transform($transform)
    {
        $this->transform = $transform;
        return $this;
    }
}